<!DOCTYPE HTML>
<html th:with="title='新增角色'" >
<head th:include="fragments/header :: header">
</head>
<body>
<div class="page-container" style="padding-top:0px;padding-bottom:0px;">
	<form action="/security/group/save" method="post" class="form form-horizontal" id="group-form">	
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名称：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text size-L" id="name" name="name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">描述：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text size-L" id="remark" name="remark">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">权限列表：</label>
			<div class="formControls col-xs-2 col-sm-4">
				<span class="select-box">
					<select class="select size-L" id="roleNames" name="roleNames" size="8">						
					</select>
				</span>				
				<input type="hidden" name="roleIds" id="roleIds" />
			</div>
			<div class="formControls col-xs-1 col-sm-1">
				<input class="btn btn-link" type="button"  onclick="showMenu();" value="选择">
			</div>
		</div>	
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary size-L radius" type="submit" value="提交">
				<input class="btn btn-primary size-L radius" type="button" onclick="closeWin()" value="关闭">
			</div>
		</div>
	</form>
</div>
<div th:include="fragments/widget :: roleTreePanel">
</div>
<script th:include="fragments/widget :: roleTreeJs" type="text/javascript">
</script>
<script type="text/javascript">
function closeWin() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
function resetForm() {
	$('#group-form')[0].reset();
	$("#roleIds").val("");
	$("#userIds").find("option").appendTo($("#userIds_to"));
	$("#roleNames").html("");
}
$(function(){	
	$('#userIds').multiselect({submitAllLeft: false, submitAllRight: false});

	$("#group-form").validate({
		rules:{	
			name:{
				required:true,
				minlength:2,
				maxlength:16
			},
			remark:{
				required:false,
				minlength:2,
				maxlength:16
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var data = $('#group-form').serialize();
			
			if ($("#roleIds").val() != "") {
				var roleIds = $("#roleIds").val().split(",");
				for(var i = 0; i < roleIds.length; i++) {
					data += "&roles["+i+"].id=" + roleIds[i];
				}
			}
				
			$.ajax({
			    type: "POST",
			    url: '/security/group/save',
			    data: data,
			    beforeSend: function () {
			    	
			    },
			    complete: function () {
			    	
			    },
			    error: function(request) {
			    	layer.alert("系统出错");
			    },
			    success: function(data) {
			    	if (data.status == 0) {
			    		refreshUParentList();
						layer.alert(data.message, function() {
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						});
					}else{
						layer.alert(data.message);
					}
			    }
			});
		}
	});
});
</script> 
</body>
</html>